package chujisuanfa;

public class StrStr {
    public static int strStr(String haystack, String needle) {
        int hlen =haystack.length();
        int nlen =needle.length();
        if(hlen<nlen) return -1;

        for(int i=0;i<=hlen-nlen;++i){
            if(haystack.substring(i,i+nlen).equals(needle)) return i; //“==”比较的是内存地址，而“equal”比较的是内容,对于str2.substring(0, 4)，虽然子字符串也为“good”，但是这个操作是新建了一个字符串
        }
        return -1;

    }
    public static boolean com(String a,String b){

        return a==b;

    }

    public static void main(String[] args) {
        String a= "aaab";
        String b= "aaab";
        System.out.println("ababaasc".substring(0,3));
        System.out.println("ababaasc".substring(0,3)=="aba");
        System.out.println("aba"=="aba");

        System.out.println(strStr("ababaasc","aas"));
    }
}
